package cc.minos.components.container
{
	import cc.minos.components.common.Arrangement;
	import flash.display.DisplayObject;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class VBox extends Container
	{
		
		protected var _arrangement:String = Arrangement.LEFT;
		
		public function VBox()
		{
			super();
			this._type = 'vbox';
		}
		
		override public function invalidate():void
		{
			var ypos:Number = paddingTop;
			var xpos:Number = paddingLeft;
			var widthValue:Number = getMaxWidth();
			
			for ( var i:int = 0 ; i < numChildren ; i++ )
			{
				var child:DisplayObject = getChildAt( i );
				
				switch ( arrangement )
				{
					case Arrangement.RIGHT: 
						xpos = paddingLeft + ( widthValue - child.width );
						break;
					case Arrangement.CENTER: 
						xpos = paddingLeft + ( widthValue - child.width ) * .5;
						break;
					case Arrangement.LEFT: 
					default: 
						xpos = paddingLeft;
						break;
				}
				
				child.x = xpos;
				child.y = ypos;
				ypos += child.height + verticalGap;
			}
			
			super.invalidate();
		}
		
		public function get gap():Number
		{
			return verticalGap;
		}
		
		public function set gap( val:Number ):void
		{
			verticalGap = val;
		}
		
		protected function getMaxWidth():Number
		{
			var max:Number = 0;
			for ( var i:int = 0 ; i < numChildren ; i++ )
			{
				var child:DisplayObject = getChildAt( i );
				max = child.width > max ? child.width : max;
			}
			return max;
		}
		
		public function get arrangement():String
		{
			return _arrangement;
		}
		
		public function set arrangement( value:String ):void
		{
			_arrangement = value;
			invalidate();
		}
	
	}

}